﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using JumJob.Models;
namespace JumJob.Controllers
{
    public class PayController : Controller
    {
         jum_jobEntities jumDb;


        public PayController() 
        {
            
            jumDb = new jum_jobEntities();
        }
        //
        // GET: /Pay/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Pay/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        public ActionResult History() 
        {
            List<Pay> pays = (from pay in jumDb.pay
                              where pay.jum_job.posted_by == User.Identity.Name
                              select pay).ToList();
            return View(pays);
        }

        //
        // GET: /Pay/Create

        public ActionResult DoPay()
        {
            return View();
        }

        public ActionResult SuccessPay() 
        {
            return View();
        }

        //
        // POST: /Pay/Create

        [HttpPost]
        public ActionResult DoPay(Pay pay)
        {
            if (ModelState.IsValid) 
            {
                pay.doPay();
                jumDb.pay.AddObject(pay);                   
                jumDb.SaveChanges();
                return RedirectToAction("SuccessPay");
            }
            return View();
        }
        
        //
        // GET: /Pay/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Pay/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Pay/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Pay/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
